#define  _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct ListNode {
	int val;
	struct ListNode* next;
};
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* detectCycle(struct ListNode* head)
{
    struct ListNode* slow = head;
    struct ListNode* fast = head;
    while (fast)
    {
        slow = slow->next;
        if (!fast->next)
        {
            return NULL;
        }
        fast = fast->next->next;
        if (fast == slow)
        {
            struct ListNode* prev = head;
            while (prev != slow)
            {
                prev = prev->next;
                slow = slow->next;
            }
            return prev;
        }
    }
    return NULL;
}
struct ListNode* detectCycle(struct ListNode* head)
{
    struct ListNode* slow = head;
    struct ListNode* fast = head;
    while (fast)
    {
        if (!fast->next)
        {
            return NULL;
        }
        fast = fast->next->next;
        if (fast = slow)
        {
            struct ListNode* prev = head;
            while (slow != prev)
            {
                prev = prev->next;
                slow = slow->next;
            }
            return prev;
        }
    }
    return NULL;
}
struct ListNode* detectCycle(struct ListNode* head)
{
    struct ListNode* slow = head;
    struct ListNode* fast = head;
    while (fast)
    {
        slow = slow->next;
        if (!fast->next)
        {
            return NULL;
        }
        fast = fast->next->next;
        if (slow != fast)
        {
            struct ListNode* prev = head;
            while (slow != prev)
            {
                slow = slow->next;
                prev = prev->next;
            }
            return prev;
        }
    }
    return NULL;
}
















